package com.miyake.loveviewweb.client.viewer;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ListBox;

public abstract class ImageToolbar extends Composite {

    public ImageToolbar() {
        HorizontalPanel panel = new HorizontalPanel();
        //panel.setWidth("100%");
        initWidget(panel);
        
        final ListBox sizeList = new ListBox();
        panel.add(new HTML("Size"));
        panel.add(sizeList);
        sizeList.addItem("Original");
        sizeList.addItem("150x100");
        sizeList.addItem("200x150");
        sizeList.addItem("300x200");
        
        sizeList.addChangeHandler(new ChangeHandler() {
            public void onChange(ChangeEvent event) {
                String s = sizeList.getItemText(sizeList.getSelectedIndex());
                if (!s.equals("Original")) {
                    String width = s.split("x")[0] + "px";
                    String height = s.split("x")[1] + "px";
                    onSizeChange(width, height);
                }
                else {
                    onSizeOriginal();
                }
            }
        });

    }

    abstract protected void onSizeOriginal();
    abstract protected void onSizeChange(String width, String height);
}
